package com.zz.ecommerce.searchManage.goods.preclassified;

import com.zz.ecommerce.common.CommonDao;
import com.zz.ecommerce.common.GridRequest;
import com.zz.ecommerce.common.GridResult;
import com.zz.ecommerce.common.bean.qdc.db.TOrderHeadQdc;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * Created by admin on 2016/3/29.
 */
@Service
public class HsCodeService {

    @Autowired
    private CommonDao commonDao;
    @Autowired
    private HsCodeDao hsCodeDao;

    public GridResult queryHsCodeList(final GridRequest request, final SComplex sComplex) {
        int count = commonDao.count("busi_param.s_complex", sComplex);
        List<TOrderHeadQdc> orderHeadList = commonDao.page("busi_param.s_complex", sComplex,
                request.getStart(), request.getEnd(),
                "");

        return new GridResult(orderHeadList, request, count);
    }

    /**
     * 查询税则
     *
     * @param request
     * @param sTraiff
     * @return
     */
    public GridResult queryTariffInfoList(final GridRequest request, final STraiff sTraiff) {
        int count = commonDao.count("BUSI_PARAM.S_TARIFF", sTraiff);
        List<TOrderHeadQdc> orderHeadList = commonDao.page("BUSI_PARAM.S_TARIFF", sTraiff,
                request.getStart(), request.getEnd(),
                "");

        return new GridResult(orderHeadList, request, count);
    }

    public GridResult queryPreHsCodeList(final GridRequest request, final SComplex sComplex) {
        String whereCond=" and  exists(select 1 from " +
                " busi_param.S_COMPLEX_tariff where busi_param.s_complex.code_ts=busi_param.S_COMPLEX_tariff.code_ts)";
        int count = commonDao.countWhere("busi_param.s_complex", sComplex, whereCond);
        List<TOrderHeadQdc> orderHeadList = commonDao.pageWhere("busi_param.s_complex", sComplex,
                request.getStart(), request.getEnd(),
                "",whereCond);

        return new GridResult(orderHeadList, request, count);
    }

    /**
     * 查询税则
     *
     * @param hsCode
     * @return
     */
    public List<Map> queryMapTariffInfoList(String hsCode) {

        return hsCodeDao.queryMapTariffInfoList(hsCode);
    }
}
